if not HST then return end

-- Determines shooting or spell casting
HST.ammos = HST.ammos or 0
HST.AmmoSlot = 0

function HST:InitEquippedAmmoCount()
    HST.ammos = self:GetEquippedAmmoCount()
end

function HST:IsPlayerAmmoRemoved()
    -- If the player has not equipped any ammo, 
    -- GetInventoryItemCount() still returns 1 instead.
    local count = GetInventoryItemCount("player", HST.AmmoSlot)
    local icon = GetInventoryItemTexture("player", HST.AmmoSlot)
    return Count == 1 and not icon
end

function HST:GetEquippedAmmoCount()
    local count = GetInventoryItemCount("player", HST.AmmoSlot)
    if HST:IsPlayerAmmoRemoved() then count = 0 end
    return count
end

function HST:CheckAmmoCountChange()
    local ammo = self:GetEquippedAmmoCount()
    if HST.ammos == ammo then 
        return false 
    end

    -- Several reasons for ammo count changes:
    -- 1. Ammo consumed;
    -- 2. Ammo removed;
    -- 3. Ammo replaced.
    -- The resulting ammo count could be more or 
    -- less than before, but it's OK.
    HST.ammos = ammo
    return true
end

function HST:BlockNonAmmoEvents(arg1)
    -- Three cases where can be considered as non-ammo-change events:
    -- 1. When arg1 is not nil, the player pick up an item from the bag;
    -- 2. Player doesn't equip any ammo;
    -- 3. Ammo count remains the same.
    if arg1 then return true end 

    if self:IsPlayerAmmoRemoved() or 
        not self:CheckAmmoCountChange() then 
        return true 
    end

    return false
end